#ifndef SERVERTHREAD_H
#define SERVERTHREAD_H

#include <QThread>
#include <QTcpSocket>
#include <QFile>
#include <QSocketNotifier>
//#include <Python.h>
#include "uart.h"
#include "readgcode.h"
#include <QMutex>
#include <QTimer>


class ServerThread : public QThread
{
    Q_OBJECT
public:
    explicit ServerThread(QObject *parent = 0,int desc=0);
    ~ServerThread();

signals:
    void out();
public slots:
    void ReceiveCmdFile();
    void readArduino();
    void sendCmdToArduino(QString command);
    void printNow();
    void stopNow();
    void recoverNow();
    void cancleNow();
    void clientDisconnect();
private:
    QTcpSocket* socket;
    readGcode* gcodes;
    QString tosend;
    bool isStop;
    QMutex mutex;
    QTimer* checkTimer;

    qint64 TotalBytes;
    qint64 bytesReceived;
    qint64 bytesToReceive;
    qint64 fileNameSize;

    qint64 mm;

    qint64 fileSize;
    qint8 receiveClass;

    QString fileName;
    QString command;
    QFile *localFile;
    QByteArray inBlock;

    QDataStream in;

    uart* uartArduino;
    QSocketNotifier *uartListen;
    QTcpSocket* uartSocket;

    void addToSender();

//    //python api
//    PyObject* pModule;
//    PyObject* pDict;
//    PyObject* pPrinter;
//    PyObject* gcoder;
//    PyObject* gcode;

//    void connectPrinter(char* dev,char* file);
//    void sendNow(QString cmd);
//    void pauseNow();
//    void resumeNow();
//    void disconnectNow();
};

#endif // SERVERTHREAD_H
